package cn.tedu;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Demo07 {
    public static void main(String[] args) {
        //获取连接
        try (Connection conn=DBUtils.getConn()){
            String sql="insert into user values(null,?,?)";
            PreparedStatement ps=conn.prepareStatement(sql);
            for (int i = 0; i <100 ; i++) {
                ps.setString(1,"name"+i);
                ps.setString(2,"pw"+i);
                //添加批量操作
                ps.addBatch();
                if (i%20==0){//避免内存溢出 每20次执行一次批量操作
                    ps.executeBatch();
                }
            }
            ps.executeBatch();//执行批量操作
        } catch (SQLException throwables) {
             throwables.printStackTrace();
        }
    }
}
